package com.filldream.sun.bean.result;


/**
 * 基础controller层向页面返回的信息
 * @author fishlord and RickSun
 * 2019-03-22 15:56
 */
public class BaseResultEntity {

    /** 错误码(供前后端)  */
    protected int code;

    /** 返回信息(供前端)  */
    protected String msg;

    /** 返回信息(英文，供前端)  */
    protected String enmsg;

    /** 报错提示(供后端)  */
    protected String errmsg;


    /**
     * 空参构造器
     */
    public BaseResultEntity(){}

    /**
     * 指定构造器
     * @param code
     * @param msg
     */
    public BaseResultEntity(int code,String msg,String enmsg){
        this.code=code;
        this.msg=msg;
        this.enmsg =enmsg;
        this.errmsg = msg;
    }

    /**
     * 指定构造器
     * @param code
     * @param msg
     */
    public BaseResultEntity(int code,String msg,String enmsg,String errmsg){
        this.code=code;
        this.msg=msg;
        this.enmsg =enmsg;
        this.errmsg = errmsg;
    }

    /**
     * 指定构造器
     * @param code
     * @param msg
     */
    public BaseResultEntity(int code,String msg){
        this.code=code;
        this.msg=msg;
        this.enmsg =null;
        this.errmsg = msg;
    }


    /**
     * 默认错误码返回
     * @param errorCode
     * @return
     */
    public static BaseResultEntity create(ErrorCode errorCode){
        return new BaseResultEntity(errorCode.getCode(),errorCode.getMsg(),errorCode.getEnmsg());
    }



    public static BaseResultEntity create(ErrorCode errorCode,String msg){
        return new BaseResultEntity(errorCode.getCode(),msg,errorCode.getEnmsg());
    }

    /**
     * 自定义错误消息
     * @param errorCode 错误编码
     * @param msg   返回信息
     * @param errmsg    返回错误信息
     * @return
     */
    public static BaseResultEntity create(ErrorCode errorCode,String msg,String errmsg){
        return new BaseResultEntity(errorCode.getCode(),msg,errorCode.getEnmsg(),errmsg);
    }


    /**
     * 默认成功
     * @return
     */
    public static BaseResultEntity success(){
        ErrorCode errorCode = ErrorCode.SUCCESS;
        return new BaseResultEntity(errorCode.getCode(),errorCode.getMsg(),errorCode.getEnmsg());
    }

    /**
     *  默认失败
     * @return
     */
    public static BaseResultEntity fail(){
        ErrorCode errorCode = ErrorCode.FAIL;
        return new BaseResultEntity(errorCode.getCode(),errorCode.getMsg(),errorCode.getEnmsg());
    }

    /**
     * 默认失败
     * @param msg
     * @return
     */
    public static BaseResultEntity fail(String msg){
        ErrorCode errorCode = ErrorCode.FAIL;
        return new BaseResultEntity(errorCode.getCode(),msg,errorCode.getEnmsg());
    }

    public boolean isOk(){
        return this.code == 0;
    }

    public Boolean getOk(){
        return null;
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getEnmsg() {
        return enmsg;
    }

    public void setEnmsg(String enmsg) {
        this.enmsg = enmsg;
    }

    public String getErrmsg() {
        return errmsg;
    }

    public void setErrmsg(String errmsg) {
        this.errmsg = errmsg;
    }
}
